package com.ruoyi.ice.result;

import com.ice.core.annotation.IceField;
import com.ice.core.annotation.IceNode;
import com.ice.core.context.IceRoam;
import com.ice.core.leaf.roam.BaseLeafRoamResult;

import com.ruoyi.common.utils.StringUtils;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;


/**
 * @author waitmoon
 */
@Data
@EqualsAndHashCode(callSuper = true)
@IceNode(name = "标准计费", desc = "标准计费")
public class AmountResult extends BaseLeafRoamResult {

    //@IceField(name = "发给谁", desc = "发放的key 如 停泊费 id")
    //private String key;
    @IceField(name = "单价", desc = "单价")
    private BigDecimal value;

    @IceField(name = "作业重量量取值", desc = "例如 berth_weight")
    private String workWeightKey;


    private BigDecimal workWeight ;

    @IceField(name = "作业天数取值", desc = "例如 berth_days")
    private String workDaysKey;


    private BigDecimal workDays;

    @Override
    protected boolean doRoamResult(IceRoam roam) {
        //Long uid = Long.valueOf(roam.getMulti(key));

        if ( value .compareTo(BigDecimal.ZERO) == -1 ) {
            return false;
        }

        if(StringUtils.isNotEmpty(workWeightKey)){
            Object workWeightValue = roam.getMulti(workWeightKey);

            if(StringUtils.isNotNull(workWeightValue)){
                workWeight = new BigDecimal(workWeightValue.toString());
            }else {
                workWeight = BigDecimal.ONE;
            }

            roam.put("workWeightKey",workWeightKey);

        }else {
            workWeight = BigDecimal.ONE;
        }

        if(StringUtils.isNotEmpty(workDaysKey)) {
            Object workDaysValue = roam.getMulti(workDaysKey);

            if (StringUtils.isNotNull(workDaysValue)) {
                workDays = new BigDecimal(workDaysValue.toString());
            } else {
                workDays = BigDecimal.ONE;
            }

            roam.put("workDaysKey",workDaysKey);

        } else {
            workDays = BigDecimal.ONE;
        }

        BigDecimal calValue = value .multiply(workWeight).multiply(workDays) ;

        roam.put("workNum1",workWeight);

        roam.put("workDays",workDays);

        roam.put("unitPrice",value);

        roam.put("result",calValue);

        return true;
    }
}
